package com.zlikun.lq;

import java.util.Arrays;
import java.util.Date;

/**
 * @author lq
 * @date 2018年1月15日 下午9:44:41
 */

public class Employee implements Comparable<Employee> {

	private Double salary;
	private Integer age;
	private Date hireDay;

	public double getSalary() {
		return salary;
	}

	public void setSalary(double salary) {
		this.salary = salary;
	}

	public Employee(double salary) {
		this.salary = salary;
	}
	
	
	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	public void addSalary(Employee e){
		e.setSalary(200);
	}
	
	public int addAge(int age){
		return age +10;
	}
	
	
	
	public Date getHireDay() {
		return hireDay;
	}

	public void setHireDay(Date hireDay) {
		this.hireDay = hireDay;
	}

	@Override
	protected Object clone() throws CloneNotSupportedException {
		// TODO Auto-generated method stub
		return super.clone();
	}

	@Override
	public int compareTo(Employee o) {

		if (this.salary > o.getSalary()) {

			return 1;
		}
		if (this.salary < o.getSalary()) {

			return -1;
		}

		return 0;
	}

	public static void main(String[] args) {

		Employee emp1 = new Employee(100);
		Employee emp2 = new Employee(200);
		System.out.println(emp1.compareTo(emp2));

		Employee[] emps = new Employee[3];
		emps[0] = new Employee(100);
		emps[1] = new Employee(300);
		emps[2] = new Employee(200);
		// 调用Arrays.sort()排序服务必须实现Comparable接口的原因：sort方法内部调用了Comparable接口中的compareTo方法,如果不实现在将Employee强转时会失败
		Arrays.sort(emps);
		for (Employee employee : emps) {
			System.out.println(employee.getSalary());
		}

		System.out.println(emp1 instanceof Comparable);

	}

}
